<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../css/oksub.css" media="all" />
		<script type="text/javascript" src="../../lib/layui/layui.js"></script>
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<script type="text/javascript" src="../../js/service.js"></script>
		<style>
			.border {
				border: solid 0.5px #d2d2d2;
			}
			
			.buttonGroup {
				text-align: center;
				margin-top: 50px;
			}
		</style>
	</head>

	<body>
		<div class="ok-body home">
			<form class="layui-form" action="">
				<input type="text" name="id" id="id" disabled="disabled" class="layui-input layui-disabled" style="display: none;">
				<div class="layui-row layui-col-space10">
					<div class="layui-col-md4">
						<div class="border">
							<div class="layui-row"><span style="color: #c2c2c2;">&nbsp;基本信息</span></div>
							<div class="layui-form-item">
								<label class="layui-form-label" id="objectName"></label>
								<div class="layui-input-inline">
									<input type="text" name="name" id="name" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">所属项目</label>
								<div class="layui-input-inline">
									<select name="belongProject" id="projectList">
										<option value=""></option>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">指派给</label>
								<div class="layui-input-inline">
									<select name="pointer" id="nameList">
										<option value=""></option>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" id="objectType"></label>
								<div class="layui-input-inline">
									<select name="type" id="TypeList">
										<option value=""></option>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">优先级:</label>
								<div class="layui-input-inline">
									<select name="priority" id="priority">
										<option value="0">未定义</option>
										<option value="1">紧急</option>
										<option value="2">严重</option>
										<option value="3">重视</option>
										<option value="4">常规</option>
									</select>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-col-md8">
						<div class="layui-row layui-col-space10">
							<div class="layui-col-md6">
								<div class="border">
									<div class="layui-row"><span style="color: #c2c2c2;">&nbsp;工时信息</span></div>
									<div class="layui-form-item">
										<label class="layui-form-label">创建时间</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input layui-disabled" id="createTime" disabled="disabled">
										</div>
									</div>

									<div class="layui-form-item">
										<label class="layui-form-label">开始时间</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" id="beginTime" name="beginTime">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">消耗时间/h</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" id="spend" name="spendTime">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" id="differTime">完成时间</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" id="finishTime" name="finishTime">
										</div>
									</div>
								</div>
							</div>
							<div class="layui-col-md6">
								<div class="border">
									<div class="layui-row"><span style="color: #c2c2c2;">&nbsp;一生之路</span></div>
									<div class="layui-form-item">
										<label class="layui-form-label">状态:</label>
										<div class="layui-input-inline">
											<select name="state" id="state">
												<option value="0"></option>
												<option value="1">待激活</option>
												<option value="2">待完成</option>
												<option value="3">待启动</option>
												<option value="4">已完成</option>
												<option value="5">已关闭</option>
												<option value="6">已审批</option>
											</select>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">由谁创建:</label>
										<div class="layui-input-inline">
											<select id="nameList3" class="layui-disabled" disabled="disabled">
												<option value=""></option>
											</select>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" id="differPep">由谁完成:</label>
										<div class="layui-input-inline">
											<select name="finisher" id="nameList1">
												<option value=""></option>
											</select>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">由谁关闭:</label>
										<div class="layui-input-inline">
											<select name="closer" id="nameList2">
												<option value=""></option>
											</select>
										</div>
									</div>
								</div>
							</div>
							<div class="layui-col-md12">
								<div class="layui-col-md8">
									<div class="border">
										<label class="layui-form-label">附件名称:</label>
										<div class="layui-input-block">
											<input type="text" class="layui-input" id="fileName">
										</div>
									</div>
								</div>
								<div class="layui-col-md4">
									<div class="border">
										<label class="layui-form-label">附件:</label>
										<button type="button" class="layui-btn" id="file"><i class="layui-icon"></i>上传文件</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-row layui-col-space10">
					<div class="layui-col-md6">
						<div class="border">
							<div class="layui-row"><span style="color: #c2c2c2;">&nbsp;描述</span></div>
							<div class="layui-form-item layui-form-text">
								<div class="layui-input-block">
									<textarea name="description" id="description" placeholder="请输入内容(限制250个字)" class="layui-textarea"></textarea>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-col-md6">
						<div class="border">
							<div class="layui-row"><span style="color: #c2c2c2;">&nbsp;备注</span></div>
							<div class="layui-form-item layui-form-text">
								<div class="layui-input-block">
									<textarea name="note" id="note" placeholder="请输入内容(限制30个字)" class="layui-textarea"></textarea>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="buttonGroup">
						<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					</div>
				</div>
			</form>
		</div>
	</body>
	<script>
		layui.use(["element", "layer", "table", "form", "laydate", "upload"], function() {
			var $ = layui.jquery;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;
			var upload = layui.upload;

			var sessionStorage = window.sessionStorage;
			var userId = sessionStorage.getItem("userId");
			var userName = sessionStorage.getItem("userName");
			var url = "";
			var typeurl = "";

			function getQueryString(name) {
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
				var r = decodeURI(window.location.href).split("?")[1];
				r = r.match(reg);
				if(r != null) {
					return unescape(r[2]);
				}    
				return null;
			};

			var ObjectId = getQueryString("id");
			var ObjectName = getQueryString("name");
			var ObjectType = getQueryString("objType");
			var ObjectTime = getQueryString("spendTime");
			var createTime = getQueryString("createTime");
			var beginTime = getQueryString("beginTime");
			var finishTime = getQueryString("finishTime");
			var creator = getQueryString("creator");
			var pointer = getQueryString("pointer");
			var finisher = getQueryString("finisher");
			var closer = getQueryString("closer");
			var belongProject = getQueryString("belongProject");
			var priority = getQueryString("priority");
			var belongProduct = getQueryString("belongProduct");
			var belongTask = getQueryString("belongTask");
			var belongDemand = getQueryString("belongDemand");
			var belongBug = getQueryString("belongBug");
			var state = getQueryString("state");
			var description = getQueryString("description");
			var note = getQueryString("note");

			if(description != null) {
				$("#description").val(description);
			}
			if(note != null) {
				$("#note").val(note);
			}
			$("#state").val(state);
			$("#priority").val(priority);
			$("#spend").val(ObjectTime);
			$("#createTime").val(createTime);
			laydate.render({
				elem: '#beginTime', //指定元素
				type: 'datetime',
				value: beginTime
			});

			switch(ObjectType) {
				case "任务":
					$("#objectName").html("任务名称:");
					$("#objectType").html("任务类型:");
					belongTask = ObjectId;
					url = "/task/update";
					typeurl = "1";
					break;
				case "BUG":
					$("#objectName").html("Bug名称:");
					$("#objectType").html("Bug类型:");
					belongBug = ObjectId;
					url = "/bug/update";
					typeurl = "2";
					break;
				case "需求":
					var approverTime = getQueryString("approverTime");
					finisher = getQueryString("approver");
					$("#objectName").html("需求名称:");
					$("#objectType").html("需求来源:");
					$("#differTime").html("审批时间");
					$("#differPep").html("由谁审批:")
					$("#finishTime").attr("name", "approverTime");
					finishTime = approverTime;
					belongDemand = ObjectId;
					url = "/demand/update";
					typeurl = "3";
					break;
			}
			laydate.render({
				elem: '#finishTime', //指定元素
				type: 'datetime',
				value: finishTime
			});
			$("#id").val(ObjectId);
			$("#name").val(ObjectName);
			getdata("/user/search", {}, "GET", function(data) {
				data = data.data;
				$.each(data, function(index, item) {
					$("#nameList").append(new Option(item.name, item.id));
					$("#nameList1").append(new Option(item.name, item.id));
					$("#nameList2").append(new Option(item.name, item.id));
					$("#nameList3").append(new Option(item.name, item.id));
				});
				$("#nameList").val(pointer);
				$("#nameList1").val(finisher);
				$("#nameList2").val(closer);
				$("#nameList3").val(creator);
				form.render();
			})
			getdata("/project/searchByPage", {}, "GET", function(data) {
				data = data.data;
				$.each(data, function(index, item) {
					$("#projectList").append(new Option(item.name, item.id));
				});
				$("#projectList").val(belongProject);
				form.render();
			})
			getdata("/type/search", {
				objType: typeurl
			}, "GET", function(data) {
				data = data.data;
				$.each(data, function(index, item) {
					$("#TypeList").append(new Option(item.name, item.id));
				});
				form.render();
			})
			upload.render({
				elem: '#file', //绑定元素

				url: 'http://localhost:9014/file/upload', //上传接口
				data: {
					"fileType": 1,
					"loginUserName": userName,
					"loginUserId": userId,
					"name": function() {
						return $("#fileName").val();
					},
					"belongProject": belongProject,
					"belongProduct": belongProduct,
					"belongTask": belongTask,
					"belongDemand": belongDemand,
					"belongBug": belongBug
				},

				accept: 'file', //允许上传的文件类型
				method: 'POST',
				done: function(res) {
					//上传完毕回调
					layer.msg(res.msg);
				},
				error: function() {
					//请求异常回调
				}
			});

			form.on('submit(formDemo)', function(data) {
				var params = data.field;
				params["loginUserName"] = userName;
				params["loginUserId"] = userId;
				getdata(url, params, "POST", function(data) {
					layer.msg(data.msg);
				})

				return false;
			});

		})
	</script>

</html>